import 'package:flutter_baichuan/models/user_model.dart';

class LoginModel {
  // 错误码
  String? errorCode;
  // 错误信息
  String? errorMessage;

  UserModel? data;

  LoginModel({this.errorCode, this.errorMessage, this.data});

  LoginModel.fromMap(Map json) {
    var code = '-1';
    var msg = '获取失败';
    if (json['errorCode'] != null) {
      code = json['errorCode'];
    }
    if (json['errorMessage'] != null) {
      msg = json['errorMessage'];
    }
    errorCode = code;
    errorMessage = msg;

    var nick = '';
    var avatarUrl = '';
    var openId = '';
    var topAccessToken = '';
    var topAuthCode = '';
    var openSid = '';

    if (json['data'] != null) {
      Map dataJs = json['data'];

      if (dataJs['nick'] != null) {
        nick = dataJs['nick'] ?? '';
      }
      if (dataJs['avatarUrl'] != null) {
        avatarUrl = dataJs['avatarUrl'] ?? '';
      }
      if (dataJs['openId'] != null) {
        openId = dataJs['openId'] ?? '';
      }
      if (dataJs['topAccessToken'] != null) {
        topAccessToken = dataJs['topAccessToken'] ?? '';
      }
      if (dataJs['topAuthCode'] != null) {
        topAuthCode = dataJs['topAuthCode'] ?? '';
      }
      if (dataJs['openSid'] != null) {
        openSid = dataJs['openSid'] ?? '';
      }
    }
    data = UserModel(
      nick: nick,
      avatarUrl: avatarUrl,
      openId: openId,
      topAccessToken: topAccessToken,
      topAuthCode: topAuthCode,
      openSid: openSid,
    );
  }

  LoginModel.fromJson(Map<String, dynamic> map) {
    this.errorCode = map['errorCode'];
    this.errorMessage = map['errorMessage'];
    this.data = map['data'];
  }

  Map<String, dynamic> toJson() {
    var data = new Map<String, dynamic>();
    data['errorCode'] = this.errorCode;
    data['errorMessage'] = this.errorMessage;
    data['data'] = this.data;
    return data;
  }

  @override
  String toString() {
    return '''
    <LoginModel>:
    errorCode: $errorCode,
    errorMessage: $errorMessage,
    data: $data
    ''';
  }
}
